

#region USING
//
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;
//
#endregion USING


namespace Gsp315_AIBehaviors
{
    public class Game1 : Microsoft.Xna.Framework.Game
    {

        #region VARIABLES
        //
        GraphicsDeviceManager graphics;
        ContentManager content;
        SpriteBatch spriteBatch;

        Background background;
        Background SeekingButton;
        MouseState mouseStateCurrent, mouseStatePrevious;

        bool move = false;
        
        Agent rock, paper, scissor;
        Controller crtl;

        //SIM_Controller_OLD controller;
        //Enemy enemy;
        //Steering steering;

        
        //
        #endregion VARIABLES


        //DEFAULT CONSTRUCTOR
        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            content = new ContentManager(Services);
            content.RootDirectory = "Content";
            this.IsMouseVisible = true;

            //Set the Window Size
            graphics.PreferredBackBufferWidth = 800;
            graphics.PreferredBackBufferHeight = 600;
        }

        
        //INIT METHOD
        protected override void Initialize()
        {
            base.Initialize();
        }

        
        //LOAD CONTENT METHOD
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            background = new Background(content.Load<Texture2D>("Space"));
            SeekingButton = new Background(content.Load<Texture2D>("StartSeekingButton"),
                                        new Vector2(((graphics.PreferredBackBufferWidth / 2) - 100), (graphics.PreferredBackBufferHeight / 2) - 25),
                                        new Vector2(200, 50));


            rock = new Agent( content.Load<Texture2D>("Rock_16x16"));
            paper = new Agent(content.Load<Texture2D>("Paper_16x16"));
            scissor = new Agent(content.Load<Texture2D>("Scissor_16x16"));

            crtl = new Controller(rock, paper, scissor);

            //controller = new SIM_Controller_OLD(rock, paper, scissor);
            //enemy = new Enemy(content.Load<Texture2D>("Enemy"), new Vector2(graphics.PreferredBackBufferWidth / 2 + 100, graphics.PreferredBackBufferHeight / 6), new Vector2(32.0f, 32.0f));
            //player = new Player(content.Load<Texture2D>("Player"), new Vector2(graphics.PreferredBackBufferWidth/2, graphics.PreferredBackBufferHeight - 60), new Vector2(32.0f, 32.0f));
            
            //greenDot = new Background(content.Load<Texture2D>("GreenDot"), enemy.Center, new Vector2(2, 2));
            // TODO: use this.Content to load your game content here
        }


        //UNLOAD CONTENT METHOD
        protected override void UnloadContent()
        {
            // TODO: Unload any non ContentManager content here
        }

        
        //UPDATE METHOD
        protected override void Update(GameTime gameTime)
        {
            KeyboardState keyboardState = Microsoft.Xna.Framework.Input.Keyboard.GetState();

            mouseStateCurrent = Mouse.GetState();

            // Allows the game to exit
            if ((GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) || keyboardState.IsKeyDown(Keys.Escape))
                this.Exit();

            
            // TODO: Add your update logic here
            if (!move)
            {
                // if the mouse position is in the sprites position
                if (mouseStateCurrent.X >= SeekingButton.Position.X &&
                    mouseStateCurrent.X <= SeekingButton.Position.X + SeekingButton.Size.X &&
                    mouseStateCurrent.Y >= SeekingButton.Position.Y &&
                    mouseStateCurrent.Y <= SeekingButton.Position.Y + SeekingButton.Size.Y &&
                    mouseStateCurrent.LeftButton == ButtonState.Pressed &&
                    mouseStatePrevious.LeftButton == ButtonState.Released)
                {
                    move = true;
                }
            }

            if (move)
            {
                crtl.Update(gameTime);
                //controller.Update(gameTime);
                //enemy.move();
                //rock.Update_Behaviour();
                //player.Seek(enemy);
            }
            //if ((player.Position + (player.Size / 2)) == (enemy.Position + (enemy.Size / 2)))
            //if (player.Position == enemy.Position) //&& (player.Position >= enemy.Position))
            //if(player.Collides(enemy))
            //{
            //    enemy.setRandomPosition();
            //}

            //update the mouse
            mouseStatePrevious = mouseStateCurrent;
            
            base.Update(gameTime);
        }

        
        //RENDER TO SCCREEN METHOD
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);
     
            spriteBatch.Begin();

                background.Draw(spriteBatch);
                crtl.Draw(spriteBatch);

                //controller.Draw(spriteBatch);
                //player.Draw(spriteBatch);
                //rock.Draw(spriteBatch);
                //enemy.Draw(spriteBatch);
                if (!move)
                {
                    SeekingButton.Draw(spriteBatch);
                }

            spriteBatch.End();
            // TODO: Add your drawing code here

            base.Draw(gameTime);
        }
    }
}
